package com.sims.action;

import java.sql.ResultSet;

import com.sims.MySQLConnBean;

public class LoginAction {
	private String userAccount;

	public String getUserAccount() {
		return userAccount;
	}

	public void setUserAccount(String userAccount) {
		this.userAccount = userAccount;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	private String userPassword;

	// struts2 的action方法
	public String execute() throws Exception {
		boolean validated = false;
		if (userAccount != null || userAccount.trim().length() > 0) {
			MySQLConnBean mySqlBean = new MySQLConnBean();
			mySqlBean.OpenConn(); // 调用MySqlBean中加载JDBC驱动的方法
			String strSql = "select user_account,user_password,user_name,activity_status from stn_user where user_account='"
					+ userAccount + "'";
			ResultSet rs = mySqlBean.executeQuery(strSql);
			while (rs.next()) {
				if ((rs.getString("user_password").equals(userPassword))
						&& "Y".equals(rs.getString("activity_status"))) {
					validated = true; // 标识为true表示验证成功通过
					break;
				}
			}
			rs.close();
			mySqlBean.closeStmt();
			mySqlBean.closeConn();
		}
		if (validated) {
			return "success";
		} else {
			return "error";
		}
	}

}
